package com.xpu.pms.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.xpu.pms.comm.http.PageInfo;
import com.xpu.pms.comm.http.QueryPage;
import com.xpu.pms.comm.http.Respond;
import com.xpu.pms.mapper.BaseRoomMapper;
import com.xpu.pms.entity.BaseRoomEntity;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.beans.factory.annotation.Autowired;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import java.util.List;
/**
 * @author 徐立彬
 * @date 2019-11-22
 */
@RestController
@RequestMapping("base/room")
public class BaseRoomController {
    @Autowired
    BaseRoomMapper baseRoomMapper;
    
    @RequestMapping("/all")
    public List<BaseRoomEntity> all() {
        List<BaseRoomEntity> list = baseRoomMapper.selectList(new QueryWrapper<>());
        return list;
    }
    
    @RequestMapping("/add")
    public Respond add(@RequestBody BaseRoomEntity entity) {
        baseRoomMapper.insert(entity);
        return new Respond();
    }
    
    @RequestMapping("/update")
    public Respond update(@RequestBody BaseRoomEntity entity) {
        baseRoomMapper.updateById(entity);
        return new Respond();
    }
    
    @RequestMapping("/del")
    public Respond del(@RequestBody BaseRoomEntity entity) {
        baseRoomMapper.deleteById(entity.getId());
        return new Respond();
    }

    @RequestMapping("/page")
    public Respond page(@RequestBody QueryPage page) {
        List<BaseRoomEntity> list= baseRoomMapper.selectPageList(page.toMap());
        int total = baseRoomMapper.selectCount(new QueryWrapper<>());
        PageInfo pi = new PageInfo(page.getPage().getIndex(),page.getPage().getSize(),total);
        return new Respond().setPage(pi).setData(list);
    }
}
